<template>
	<view class="index-list animate__animated animate__fadeInLeft animate__slow" @tap="opendetail">
		<!-- 头像 昵称 -->
		<view class="index-list1 u-f-ac u-f-jsb">
			<!-- 头像、昵称 -->
			<view class="u-f-ac">
				<image :src="item.avatar" mode="widthFix" lazy-load></image>
				{{item.nickname}}
			</view>
			<!-- 是否关注 -->
			<view class="u-f-ac" v-show="item.isfollow === 0" @tap.stop="follow()">
				<view class="icon iconfont icon-zengjia1">关注</view>
			</view>
		</view>
		<!-- 标题 -->
		<view class="index-list2">{{item.title}}</view>
		<!-- 封面图 -->
		<view class="index-list3 u-f-ajc">
			<image :src="item.cover" mode="widthFix" lazy-load></image>
			<!-- 视频 -->
			<template v-if="item.type === 'video'">
				<view class="index-list-play icon iconfont icon-bofang"></view>
				<view class="index-list-playinfo">
					{{item.playnum}}次播放 {{item.long}}
				</view>
			</template>
		</view>
		<!-- 点赞、转发 -->
		<view class="index-list4 u-f-ac u-f-jsb">
			<view class="u-f-ac">
				<!-- 顶 -->
				<view class="u-f-ac" :class="{'active':(item.likeinfo.index === 1)}" 
				@tap.stop="operate('like')">
					<view class="icon iconfont icon-icon_xiaolian-mian"></view>
					{{item.likeinfo.likenum}}
				</view>
				<!-- 踩 -->
				<view class="u-f-ac" :class="{'active':(item.likeinfo.index === 2)}"
				@tap.stop="operate('dislike')">
					<view class="icon iconfont icon-kulian"></view>
					{{item.likeinfo.dislikenum}}
				</view>
			</view>
			<view class="u-f-ac">
				<!-- 评论 -->
				<view class="u-f-ac">
					<view class="icon iconfont icon-pinglun"></view>
					{{item.commentnum}}
				</view>
				<!-- 转发 -->
				<view class="u-f-ac">
					<view class="icon iconfont icon-zhuanfa"></view>
					{{item.sharenum}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: Object,
			index: Number
		},
		methods:{
			/* 关注 */
			follow(){
				// todo
				this.item.isfollow = 1;
				uni.showToast({
					title:'关注成功'
				})
			},
			/* 顶、踩操作 */
			operate(type){
				let currentIdnex = this.item.likeinfo.index;
				switch(type) {
					case 'like':
						if(currentIdnex === 1){
							return;
						}
						this.item.likeinfo.likenum ++;
						if(currentIdnex === 2){
							this.item.likeinfo.dislikenum --;
						}
						this.item.likeinfo.index = 1;
						break;
					case 'dislike':
						if(currentIdnex === 2){
							return;
						}
						this.item.likeinfo.dislikenum ++;
						if(currentIdnex === 1){
							this.item.likeinfo.likenum --;
						}
						this.item.likeinfo.index = 2;
						break;
				}
			},
			opendetail(){
				uni.navigateTo({
					url: '../../pages/detail/detail?detailData=' + JSON.stringify(this.item)
				})
			}
		}
	}
</script>

<style scoped>
	.index-list{
		padding: 20upx;
		border-bottom: 1upx solid #EEEEEE;
	}
	.index-list1>view:first-child image{
		width: 85upx;
		height: 85upx;
		border-radius: 100%;
		margin-right: 10upx;
	}
	.index-list1>view:last-child{
		background: #F4F4F4;
		border-radius: 5upx;
		padding: 0 10upx;
	}
	.index-list2{
		font-size: 32upx;
	}
	.index-list2,.index-list3{
		padding-top: 15upx;
	}
	.index-list3{
		/* 相对定位 */
		position: relative;
	}
	.index-list3>image{
		width: 100%;
		border-radius: 20upx;
	}
	.index-list4{
		padding: 15upx 0;
		color: #999999;
	}
	.index-list4>view>view:first-child,.index-list4>view>view>view{
		margin-right: 10upx;
	}
	.index-list4 .active,.index-list4 .active>view{
		color: #FFB400;
	}
	.index-list-play{
		position: absolute;
		font-size: 140upx;
		color: #FFFFFF;
	}
	.index-list-playinfo{
		position: absolute;
		background: rgba(51,51,51,0.72);
		color: #FFFFFF;
		bottom: 8upx;
		right: 8upx;
		border-radius: 40upx;
		font-size: 22upx;
		padding: 0 10upx;
	}
</style>
